connection: clean up failed heartbeat sends#876
Conversation
892831d to
358e016
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes a heartbeat failure edge case where send_msg() can fail after a request id has been reserved, leaking the request id / callback registration and (for control connections) potentially leaving in_flight incorrectly incremented. It also adds a regression test to ensure request-id and in-flight bookkeeping is restored after a failed heartbeat send.
Changes:
- Update
HeartbeatFutureto unwind_requestsregistration and return the reserved request id whensend_msg()fails. - Ensure
in_flightis released directly only for control connections (since the control-connection owner’sreturn_connection()doesn’t decrementin_flight). - Add a unit test covering failed heartbeat send cleanup.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
cassandra/connection.py |
Adds failure-path cleanup in HeartbeatFuture for send_msg() exceptions (request id + _requests unwind; in_flight handling for control connections). |
tests/unit/test_connection.py |
Adds regression test ensuring request id pool, _requests, and in_flight are consistent after a heartbeat send failure. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Keep heartbeat request-id and in-flight bookkeeping consistent when send_msg() fails.\n\nHandle the control-connection in_flight release separately from HostConnection cleanup.
358e016 to
6ad10b4
Compare
|
is this the right way to fix it? |
Can't agree more, there has to be an infrastructure that would handle request scheduling, executing, failing in respect of borrowing/returning request_id, tracking in_flight, etc. |
Fixes #875.
Heartbeat sends can fail after a request id has already been reserved. This change keeps the request-id pool and in-flight accounting consistent across that failure path, and avoids double-releasing the slot on the control-connection branch.
Changes:
send_msg()fails